
document.addEventListener("DOMContentLoaded", function () {
    // 表单提交时的验证
    const form = document.querySelector(".add-member-form");
    form.addEventListener("submit", function (e) {
        const userName = document.querySelector("#userName").value;
        const phoneNumber = document.querySelector("#phoneNumber").value;

        if (userName.trim() === "" || phoneNumber.trim() === "") {
            alert("用户名和电话号码不能为空！");
            e.preventDefault();
        }
    });

    // 取消按钮点击事件
    const cancelButton = document.querySelector(".cancel-button");
    cancelButton.addEventListener("click", function (e) {
        if (confirm("确定要取消添加会员吗？")) {
            window.location.href = "<%=request.getContextPath()%>/members";
        }
    });
});